package com.example.statemachine.machine.base;

import lombok.Data;

import java.io.Serializable;

/**
 * @author jianwei.wang
 * @version v1.0
 * @date 2019/5/8 17:49
 **/
@Data
public class FsmResBody<T> implements Serializable {

    private static final long serialVersionUID = -7208197567139439680L;
    private int code;
    private String msg;

    private T data;


    public FsmResBody(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public FsmResBody(FsmResCode fsmResCode) {
        this.code = fsmResCode.getCode();
        this.msg = fsmResCode.getInfo();
    }


    public static FsmResBody success(){
        return new FsmResBody(FsmResCode.SUCCESS);
    }
    public static FsmResBody success(Object data){
        FsmResBody body = new FsmResBody(FsmResCode.SUCCESS);
        body.setData(data);
        return body;
    }
    public static FsmResBody notEvent(){
        return new FsmResBody(FsmResCode.NO_EVENT);
    }
    public static FsmResBody notTempStorage(){
        return new FsmResBody(FsmResCode.NOT_TEMP_STORAGE);
    }
    public static FsmResBody notSubmit(){
        return new FsmResBody(FsmResCode.NOT_SUBMIT);
    }
    public static FsmResBody notReview(){
        return new FsmResBody(FsmResCode.NOT_REVIEW);
    }
    public static FsmResBody notAntiReview(){
        return new FsmResBody(FsmResCode.NOT_ANTI_REVIEW);
    }
    public static FsmResBody notCancel(){
        return new FsmResBody(FsmResCode.NOT_CANCEL);
    }
    public static FsmResBody notWithDraw(){
        return new FsmResBody(FsmResCode.NOT_WITH_DRAW);
    }

    public static FsmResBody error() {
        return new FsmResBody(FsmResCode.ERROR);
    }
    public static FsmResBody error(String message) {
        return new FsmResBody(FsmResCode.ERROR.getCode(),message);
    }
    public static FsmResBody error(int code,String message) {
        return new FsmResBody(code,message);
    }
}
